const BehaviorAll = require("../../../behaviors/behavior_all.js");
const BehaviorAddress = require("../../../template/address/behavior.js");
const ServiceOrder = require("../../../service/service_order.js");
const ServiceScore = require("../../../service/service_score.js");

Component({
  /**
   * behaviors
   */
  behaviors: [BehaviorAll, BehaviorAddress],
  /**
   * 页面的初始数据
   */
  data: {
    triggerSubmitFlag: false,
    score: 0,
    amount: 0,
  },
  /**
   * 方法
   */
  methods: {
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
      const _this = this;
      /* 地址配置 */
      _this.setData({ 
        b_address_addressExistDefaultHideAddShowFlag: true,
        b_address_addressInfoShowFlag: true,
        b_address_addressInfoModifyShowFlag: true,
        b_address_addressInfoListShowFlag: true,
        //
        b_address_addressServiceCreateFlag: false,
        b_address_addressServiceModifyFlag: false,
        b_address_addressServiceDeleteFlag: false,
        //
        b_address_addressListSelectShowFlag: false,
        b_address_addressListEditShowFlag: true,
        b_address_addressListDeleteShowFlag: true
      })
    },
    /**
     * 提交
     */
    car_onSubmit: function(e){
      const _this = this;
      const address = _this.data.b_address_addressData;
      // 验证地址
      if (!_this.b_address_validateAddressData(e)) {
        return;
      }
      // 创建订单
      const products = e.detail.selectedData;
      ServiceOrder.createPack(
        products,
        address, 
        function(data){
          e.detail.callback();
          wx.navigateTo({
            url: '../orderPayType/orderPayType?orderId=' + data.id,
          })
      });
    },
    /**
     * 激活提交
     */
    onTriggerSubmit: function(e){
      this.setData({ triggerSubmitFlag: true })
    },
    /**
     * 数据改变
     */
    car_onChange: function(e){
      const _this = this;
      _this.setData({
        score: e.detail.total,
        amount : e.detail.amount
      })
    }

  }

})